<?php

$timestamp = time();
$errmsg = '';

$dberror = $this->error();
$dberrno = $this->errno();


if($message) {
	$errmsg = "<b>Myframe! info</b>: $message\n\n";
}
if(isset($GLOBALS['_DSESSION']['discuz_user'])) {
	$errmsg .= "<b>User</b>: ".htmlspecialchars($GLOBALS['_DSESSION']['discuz_user'])."\n";
}
if($sql) {
	$errmsg .= "<b>SQL</b>: ".htmlspecialchars($sql)."\n";
}
$errmsg .= "<b>Error</b>:  $dberror\n";
$errmsg .= "<b>Errno.</b>:  $dberrno";

echo "</table></table></table></table></table>\n";
echo "<p style=\"font-family: Verdana, Tahoma; font-size: 11px; background: #FFFFFF;\">";
echo nl2br($errmsg);

$errlog = array();
if(@$fp = fopen(WEB_ROOT.'./forumdata/dberror.log', 'r')) {
	while((!feof($fp)) && count($errlog) < 20) {
		$log = explode("\t", fgets($fp, 50));
		if($timestamp - $log[0] < 86400) {
			$errlog[$log[0]] = $log[1];
		}
	}
	fclose($fp);
}

if(!in_array($dberrno, $errlog)) {
	$errlog[$timestamp] = $dberrno;
	@$fp = fopen(WEB_ROOT.'./dberror.log', 'w');
	@flock($fp, 2);
	foreach(array_unique($errlog) as $dateline => $errno) {
		@fwrite($fp, "$dateline\t$errno");
	}
	@fclose($fp);
	if(function_exists('errorlog')) {
		errorlog('MySQL', basename($GLOBALS['_SERVER']['PHP_SELF'])." : $dberror - ".cutstr($sql, 120), 0);
	}
} else {
	echo '<br /><br />Similar error report has been dispatched to administrator before.';
}

echo '</p>';

exit();

?>
